package cn.itcast.job;


import cn.itcast.domain.cargo.Export;
import cn.itcast.service.cargo.ExportService;
import cn.itcast.vo.ExportResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.cxf.jaxrs.client.WebClient;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("exportJob")
public class ExportJob {

    @Reference
    private ExportService exportService;

    public void exportE(){

       List<Export> exportList = exportService.findByState(5L);
        System.out.println(exportList);
        for (Export export : exportList) {
            //从海关项目获取结果
            try {
                ExportResult exportResult = WebClient.create("http://localhost:9090/ws/export/ep/" + export.getId()).get(ExportResult.class);
                if (exportResult!=null){
                    exportService.updateE(exportResult);
                }
            } catch (Exception e) {
                System.out.println(export.getId()+"no result...........");
            }
        }
    }

}
